#include "GraphicManager.h"
#include <GL/glut.h>
    

//Initializate the graphic manager
void cGraphicManager::Init()
{
  //Set Tile sizes
  muiTileHeight = 24;
  muiTileWidth = 24;

  //Establish game height and width
  muiGameWidth = 640;
  muiGameHeight = 480;

  //Establish initial offset
  muiScreenXOffset = 0;
  muiScreenYOffset = 0;
  
  //Clear screen
  glClearColor(0.0f,0.0f,0.0f,0.0f);

  //Set the camera
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

  
	glOrtho(muiScreenXOffset, muiScreenXOffset + muiGameWidth,
    muiScreenYOffset + muiGameHeight, muiScreenYOffset,0,1);
	
  //Establish alpha test
  glMatrixMode(GL_MODELVIEW);
	glAlphaFunc(GL_GREATER, 0.05f);
	glEnable(GL_ALPHA_TEST);
}

//Deinitializate the Graphic Manager
void cGraphicManager::Deinit()
{
 
}

//Initialize frame
void cGraphicManager::InitFrame()
{
  //Establish the camera
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(muiScreenXOffset, muiScreenXOffset + muiGameWidth, 
    muiScreenYOffset + muiGameHeight, muiScreenYOffset,
    0, 1);
  
  //Clear the buffer and load the identity
  glMatrixMode(GL_MODELVIEW);
  glClear(GL_COLOR_BUFFER_BIT);	
	glLoadIdentity();
}

//Swap buffers
void cGraphicManager::SwapBuffers()
{
  //Swap buffers
  glutSwapBuffers();
}
